package huachenxing.mimi520.option.models
{
	import mx.utils.StringUtil;
	
	import huachenxing.mimi520.tools.ConfigFile;
	
	public class QueryModel
	{
		private static var months:String = "";
		public static const monthVec:Vector.<Date> = new Vector.<Date>();
		
		public static function fromConfig():void
		{
			var config:ConfigFile = new ConfigFile("query");
			config.read();
			
			for(var key:String in config)
			{
				var value:String = config[key];
				try { QueryModel[key] = value;
				} catch (e) {}
			}
			
			monthVec.length = 0;
			if(months.length > 0)
			{
				var monthArr:Array = months.split(",");
				for each(var month:String in monthArr)
				{
					month = StringUtil.trim(month);
					var monthDate:Date = new Date(int(month.substr(0, 4)), int(month.substr(4)));
					monthVec.push(monthDate);
				}
			}
		}
		
		public static function toConfig():void
		{
			var monthArr:Array = [];
			for each(var monthDate:Date in monthVec)
			{
				monthArr.push(monthDate.fullYear.toString()+ monthDate.month.toString());
			}
			months = monthArr.join(",");
			
			var config:ConfigFile = new ConfigFile("query");
			config["months"] = QueryModel.months;
			config.write();
		}
	}
}